<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/7/20
  Time: 14:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme()
            +"://"
            +request.getServerName()
            + ":"
            +request.getServerPort()
            +request.getContextPath()
            +"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>投票信息</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/webjars/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">
        setInterval("ajax()",1000);
        function ajax() {
                $.getJSON("voteServlet", "action=queryCount", function (data) {
                    if(data!=null) {
                        $.each(data, function (i, item) {
                            var candidateId = item.candidateId;
                            $("#" + candidateId).html(item.count + "票");
                        });
                    }
                });
        }
    </script>
</head>
<body>
<div>项目描述:</div>
<br>
<div>${sessionScope.project.information}</div>
    <br>
    <c:if test="${empty sessionScope.votes}">
        该项目还没有添加任何投票
    </c:if>
    <c:if test="${not empty sessionScope.votes}">
<table>
    <c:forEach items="${sessionScope.votes}" var="entry">
                第${entry.num}轮投票:${entry.name}<c:if test="${entry.voteStatus==0}">
                <br>状态:未开始
        <br>
            选项如下:<br>
                <c:forEach items="${sessionScope.candidates[entry.voteId]}" var="tmp">
                    ${tmp.name}<br>
                </c:forEach>
            </c:if>
        <c:if test="${entry.voteStatus==1}">
            <br>状态:进行中
            <br>
            选项及票数如下:<br>
                <c:forEach items="${sessionScope.candidates[entry.voteId]}" var="tmp">
                    ${tmp.name}:<div id="${tmp.candidateId}">${tmp.count}票</div><br>
                </c:forEach>
        </c:if>
        <c:if test="${entry.voteStatus==2}">
                <br>状态:已结束
                <br>
                选项及票数如下:<br>
                <c:forEach items="${sessionScope.candidates[entry.voteId]}" var="tmp">
                    ${tmp.name}:${tmp.count}票<br>
                </c:forEach>
               票数最多的是:${entry.winner}
                <br>
        </c:if>
        <br>
    </c:forEach>
</table>
</c:if>
<br/>
<a href="user/home.jsp">返回</a>
</body>
</html>
